﻿using Ewell.BizComponent.UI.Core.VievModel;
using Ewell.BizComponent.UI.PatientBanner.ViewModel;
using Ewell.BizComponent.UI.SearchPersonCom.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Ewell.BizComponent.UI.Reserve.ViewModel
{
    /// <summary>
    /// 患者预约
    /// </summary>
    public class EncounterReserveVm:ViewModelBase
    {
        /// <summary>
        /// 外部调用请求
        /// </summary>
        public OutpReserveRequestVm outpReserveRequestVm { get; set; }
        /// <summary>
        /// 患者Banner
        /// </summary>
        private PatientBannerVm _patientBannerVm;
        public PatientBannerVm patientBannerVm
        {
            get => _patientBannerVm;
            set
            {
                if (value != _patientBannerVm)
                {
                    _patientBannerVm = value;
                    OnPropertyChanged(nameof(patientBannerVm));
                }
            }
        }
        /// <summary>
        /// 门诊预约
        /// </summary>
        private OutpReserveVm _outpReserveVm;
        public OutpReserveVm outpReserveVm
        {
            get => _outpReserveVm;
            set
            {
                if(_outpReserveVm != value)
                {
                    _outpReserveVm = value;
                    OnPropertyChanged(nameof(outpReserveVm));
                }
            }
        }
        /// <summary>
        /// 检索组件
        /// </summary>
        private SearchPersonComVm _searchPersonComVm;
        public SearchPersonComVm searchPersonComVm
        {
            get => _searchPersonComVm;
            set
            {
                if (_searchPersonComVm != value)
                {
                    _searchPersonComVm = value;
                    OnPropertyChanged(nameof(searchPersonComVm));
                }
            }
        }
        /// <summary>
        /// 检索患者列表显示
        /// </summary>
        private Visibility _patiListVisib;
        public Visibility patiListVisib
        {
            get => _patiListVisib;
            set
            {
                if(value != _patiListVisib)
                {
                    _patiListVisib = value;
                    OnPropertyChanged(nameof(patiListVisib));
                }
            }
        }

        public EncounterReserveVm()
        {
            searchPersonComVm = new SearchPersonComVm();
            outpReserveVm = new OutpReserveVm();
            patientBannerVm = new PatientBannerVm();
            patiListVisib = Visibility.Collapsed;
            searchPersonComVm.SearchFinashHandle += (s) =>
            {
                if (s.patientVmResponse == null) return;
                if (s.patientVmResponse.Count == 1)
                {
                    if(this.patientBannerVm==null) this.patientBannerVm= new PatientBannerVm();
                    this.patientBannerVm.patientVm = s.patientVmResponse.FirstOrDefault();
                    outpReserveVm.patientVm = s.patientVmResponse.FirstOrDefault();
                }
                if (s.patientVmResponse.Count > 1)
                {
                    patiListVisib=Visibility.Visible;
                }
            };
        }
    }
}
